package com.fourgirls.xiaoxiang.controller;

import com.fourgirls.xiaoxiang.exception.Result;
import com.fourgirls.xiaoxiang.pojo.Shopping.ShoppingVo;
import com.fourgirls.xiaoxiang.pojo.Shopping.UserNameShoppingVo;
import com.fourgirls.xiaoxiang.pojo.ShoppingCart.ShoppingCartIdVo;
import com.fourgirls.xiaoxiang.pojo.ShoppingCart.ShoppingCartVo;
import com.fourgirls.xiaoxiang.pojo.ShoppingCart.UserNameShoppingCartVo;
import com.fourgirls.xiaoxiang.service.Shopping.UserShoppingService;
import com.fourgirls.xiaoxiang.service.ShoppingCart.UserShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class ShoppingCartController {

    @Autowired
    UserShoppingCartService userShoppingCartService;

    //---------------------------------------------------------------查询分割线--------------------------------------------------------

    /**
     * 查询address表中的所有数据(一对多的级联，查询user表中用户对应的收货地址)
     *
     * @return 查询的数据
     */
    @RequestMapping("findAllUserShoppingCart")
    public Result findAllUserShoppingCart(@RequestBody UserNameShoppingCartVo userNameShoppingCartVo) {
        return Result.ok().put("data", userShoppingCartService.findAllUserShopping(userNameShoppingCartVo));
    }

    //---------------------------------------------------------------增加分割线--------------------------------------------------------

    /**
     * 往shopping表中的增加一条数据
     *
     * @return 查询的数据
     */
    @RequestMapping("addShoppingCart")
    public Result addShoppingCart(@RequestBody ShoppingCartVo shoppingCartVo) {
        return Result.ok().put("data", userShoppingCartService.addShoppingCart(shoppingCartVo));
    }

    //---------------------------------------------------------------删除分割线--------------------------------------------------------

    /**
     * 往shopping表中的删除一条数据
     *
     * @return 查询的数据
     */
    @RequestMapping("deleteShoppingCart")
    public Result deleteShoppingCart(@RequestBody ShoppingCartIdVo shoppingCartIdVo) {
        return Result.ok().put("data", userShoppingCartService.deleteShoppingCart(shoppingCartIdVo));
    }
}
